/*
 * Script.cpp
 *
 *  Created on: 28 жовт. 2012
 *      Author: Houdini
 */

#include "Script.h"

namespace PInter
{

PyObject* Script::convertToPyType(std::string value)
{
	return PyUnicode_FromString(value.c_str());
}

PyObject* Script::convertToPyType(double value)
{
	return PyFloat_FromDouble(value);
}

PyObject* Script::convertToPyType(int value)
{
	return PyLong_FromLong(value);
}

Script::Script(std::string Name):pValue(nullptr), pArgs(nullptr), name(Name)
{
	Py_Initialize();
	pName = PyUnicode_FromString(name.c_str());
	pModule = PyImport_Import(pName);
	Py_DECREF(pName);

	if (pModule == NULL)
		throw ScriptNotFound();
}

Script::~Script()
{
	Py_XDECREF(pFunc);
	Py_DECREF(pModule);

	Py_Finalize();
}

} /* namespace PInter */
